package leetcode_数与位._01数字的位操作;

/**
 * @author yzh
 * @data 2021/3/24 19:45
 * 七进制数
 * 思路
 */
public class _504_七进制数 {
    public static void main(String[] args) {
        System.out.println(new _504_七进制数().convertToBase7(-7));
    }

    public String convertToBase7(int num) {
        if (num == 0) return "0";
        boolean flag = num < 0;
        num = Math.abs(num);
        StringBuilder ans = new StringBuilder();
        while (num != 0) {
            ans.append(num % 7);
            num /= 7;
        }
        if (flag) ans.append("-");
        return ans.reverse().toString();
    }
}
